package com.songtai.action.front;

import java.util.ArrayList;
import java.util.List;

import com.songtai.action.SongtaiActionSupport;
import com.songtai.po.Introduce;
import com.songtai.po.Node;
import com.songtai.po.PhotoObj;
import com.songtai.po.PublicObj;
import com.songtai.pojo.NodeView;
import com.songtai.service.ImageService;
import com.songtai.service.IntroduceService;
import com.songtai.service.NodeService;
import com.songtai.service.PublicObjService;
import com.songtai.util.CommenUtil;
import com.songtai.util.Pager;
import com.songtai.util.StringUtil;

/**
 * @author zzy
 * 
 */
public class IntroduceAction extends SongtaiActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1070611441749620230L;
	private int parent;
	private List<NodeView> nodes;
	private Introduce introduce;
	private Long nodeid;
	private NodeService nodeService;
	private Node currentNode;
	private IntroduceService introduceService;
	private ImageService imageService;
	private PhotoObj synopsis;
	private PublicObjService publicObjService;
	private PublicObj culture;
	private Pager<PhotoObj> envs;
	private Pager<PhotoObj> elites;
	private int currentPage;
	private List<PhotoObj> sliderList;
	// 图片幻灯片ID
	private Long slider_id = 2L;

	private String iid;

	private PhotoObj design;
	private PublicObj pub;

	private List<PublicObj> qq;

	public String introduce() throws Exception {
		String result = SUCCESS;
		nodeid = nodeid == null ? 6L : nodeid;
		int type = Integer.parseInt(nodeid.toString());
		switch (type) {
		// 公司环境
		case 4:
			get_Env();
			result = INPUT;
			break;
		// 公司文化
		case 5:
			result = LOGIN;
			get_Culture();
			break;
		// 公司简介
		case 6:
			result = SUCCESS;
			get_Synopsis();
			break;
		// 团队精英
		case 8:
			result = NONE;
			get_Elite();
			break;
		default:
			result = SUCCESS;
			get_Synopsis();
			nodeid = 6L;
			break;
		}
		// 读取幻灯片
		sliderList = imageService.getImageByNodeid(slider_id, 10, PhotoObj.TYPE_SLIDER);
		pub = publicObjService.getObjByNid("21");
		qq = publicObjService.getObjsByNid("23");
		return result;
	}

	private void get_Elite() {
		if (currentPage < 1) {
			currentPage = 1;
		}
		int pageSize = 4;
		elites = imageService.getAllImage(currentPage, pageSize, PhotoObj.TYPE_DESIGNER, nodeid);
		elites.setPageSize(pageSize);
	}

	private void get_Synopsis() {
		List<PhotoObj> list = imageService.getImageByNodeid(nodeid, 1, PhotoObj.TYPE_COMPANY_INTROUCE);
		if (list != null && !list.isEmpty()) {
			synopsis = list.get(0);
		}
	}

	private void get_Culture() {
		culture = publicObjService.getObjByNid(nodeid.toString());
	}

	private void get_Env() {
		if (currentPage < 1) {
			currentPage = 1;
		}
		int pageSize = 4;
		envs = imageService.getAllImage(currentPage, pageSize, PhotoObj.TYPE_COMPANY_ENV, nodeid);
		envs.setPageSize(pageSize);
	}

	public String getDesigner() {

		this.design = imageService.getImageById(iid);
		pub = publicObjService.getObjByNid("21");
		qq = publicObjService.getObjsByNid("23");
		// 读取幻灯片
		sliderList = imageService.getImageByNodeid(slider_id, 10, PhotoObj.TYPE_SLIDER);
		return SUCCESS;
	}

	public String certificate()throws Exception{
		this.design = imageService.getImageById(iid);
		pub = publicObjService.getObjByNid("21");
		qq = publicObjService.getObjsByNid("23");
		// 读取幻灯片
		sliderList = imageService.getImageByNodeid(slider_id, 10, PhotoObj.TYPE_SLIDER);
		return SUCCESS;
	}
	
	/**
	 * @return the parent
	 */
	public int getParent() {
		return parent;
	}

	/**
	 * @param parent
	 *            the parent to set
	 */
	public void setParent(int parent) {
		this.parent = parent;
	}

	/**
	 * @return the nodes
	 */
	public List<NodeView> getNodes() {
		return nodes;
	}

	/**
	 * @param nodes
	 *            the nodes to set
	 */
	public void setNodes(List<NodeView> nodes) {
		this.nodes = nodes;
	}

	/**
	 * @return the introduce
	 */
	public Introduce getIntroduce() {
		return introduce;
	}

	/**
	 * @param introduce
	 *            the introduce to set
	 */
	public void setIntroduce(Introduce introduce) {
		this.introduce = introduce;
	}

	/**
	 * @return the nodeid
	 */
	public Long getNodeid() {
		return nodeid;
	}

	/**
	 * @param nodeid
	 *            the nodeid to set
	 */
	public void setNodeid(Long nodeid) {
		this.nodeid = nodeid;
	}

	/**
	 * @return the nodeService
	 */
	public NodeService getNodeService() {
		return nodeService;
	}

	/**
	 * @param nodeService
	 *            the nodeService to set
	 */
	public void setNodeService(NodeService nodeService) {
		this.nodeService = nodeService;
	}

	/**
	 * @return the introduceService
	 */
	public IntroduceService getIntroduceService() {
		return introduceService;
	}

	/**
	 * @param introduceService
	 *            the introduceService to set
	 */
	public void setIntroduceService(IntroduceService introduceService) {
		this.introduceService = introduceService;
	}

	/**
	 * @return the currentNode
	 */
	public Node getCurrentNode() {
		return currentNode;
	}

	/**
	 * @param currentNode
	 *            the currentNode to set
	 */
	public void setCurrentNode(Node currentNode) {
		this.currentNode = currentNode;
	}

	/**
	 * @return the imageService
	 */
	public ImageService getImageService() {
		return imageService;
	}

	/**
	 * @param imageService
	 *            the imageService to set
	 */
	public void setImageService(ImageService imageService) {
		this.imageService = imageService;
	}

	/**
	 * @return the publicObjService
	 */
	public PublicObjService getPublicObjService() {
		return publicObjService;
	}

	/**
	 * @param publicObjService
	 *            the publicObjService to set
	 */
	public void setPublicObjService(PublicObjService publicObjService) {
		this.publicObjService = publicObjService;
	}

	/**
	 * @param culture
	 *            the culture to set
	 */
	public void setCulture(PublicObj culture) {
		this.culture = culture;
	}

	/**
	 * @return the envs
	 */
	public Pager<PhotoObj> getEnvs() {
		return envs;
	}

	/**
	 * @param envs
	 *            the envs to set
	 */
	public void setEnvs(Pager<PhotoObj> envs) {
		this.envs = envs;
	}

	/**
	 * @return the elites
	 */
	public Pager<PhotoObj> getElites() {
		return elites;
	}

	/**
	 * @param elites
	 *            the elites to set
	 */
	public void setElites(Pager<PhotoObj> elites) {
		this.elites = elites;
	}

	/**
	 * @return the culture
	 */
	public PublicObj getCulture() {
		return culture;
	}

	/**
	 * @return the currentPage
	 */
	public int getCurrentPage() {
		return currentPage;
	}

	/**
	 * @param currentPage
	 *            the currentPage to set
	 */
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	/**
	 * @return the sliderList
	 */
	public List<PhotoObj> getSliderList() {
		return sliderList;
	}

	/**
	 * @param sliderList
	 *            the sliderList to set
	 */
	public void setSliderList(List<PhotoObj> sliderList) {
		this.sliderList = sliderList;
	}

	/**
	 * @return the synopsis
	 */
	public PhotoObj getSynopsis() {
		return synopsis;
	}

	/**
	 * @param synopsis
	 *            the synopsis to set
	 */
	public void setSynopsis(PhotoObj synopsis) {
		this.synopsis = synopsis;
	}

	/**
	 * @return the iid
	 */
	public String getIid() {
		return iid;
	}

	/**
	 * @param iid
	 *            the iid to set
	 */
	public void setIid(String iid) {
		this.iid = iid;
	}

	/**
	 * @return the design
	 */
	public PhotoObj getDesign() {
		return design;
	}

	/**
	 * @param design
	 *            the design to set
	 */
	public void setDesign(PhotoObj design) {
		this.design = design;
	}

	/**
	 * @return the pub
	 */
	public PublicObj getPub() {
		return pub;
	}

	/**
	 * @param pub
	 *            the pub to set
	 */
	public void setPub(PublicObj pub) {
		this.pub = pub;
	}

	public Pager<PhotoObj> cutString(Pager<PhotoObj> obj) {
		if (obj != null && obj.getDatas() != null && !obj.getDatas().isEmpty()) {
			List<PhotoObj> old = obj.getDatas();
			List<PhotoObj> newone = new ArrayList<PhotoObj>();
			for (PhotoObj o : old) {
				PhotoObj new_o = new PhotoObj();
				new_o.setTitle(o.getTitle());
				new_o.setId(o.getId());
				new_o.setNid(o.getNid());
				new_o.setPath(o.getPath());
				if (!CommenUtil.isEmpty(o.getElseContent())) {
					new_o.setElseContent(StringUtil.abbreviate(StringUtil.Html2Text(o.getElseContent()), 60, "..."));
				}
				new_o.setInsertDate(o.getInsertDate());
				newone.add(new_o);
			}
			obj.setDatas(newone);
		}
		return obj;
	}

	public List<PublicObj> getQq() {
		return qq;
	}

	public void setQq(List<PublicObj> qq) {
		this.qq = qq;
	}

}
